package cn.lf.android.lawfirm.notice.view;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

import cn.lf.android.lawfirm.R;
import cn.lf.android.lawfirm.changeapproval.ChangeApprovalActivity;
import cn.lf.android.lawfirm.distribution.DistributionActivity;
import cn.lf.android.lawfirm.home.modle.Message;
import cn.lf.android.lawfirm.notice.NoticeListActivity;
import cn.lf.android.lawfirm.outgoingregistration.OutGoingInfoActivity;
import cn.lf.android.lawfirm.undertake.approval.UndertakeActivity;
import cn.lf.android.lawfirm.upgrade.approval.UpgradeActivity;

import static android.R.attr.onClick;
import static cn.lf.android.lawfirm.R.id.head_left;
import static cn.lf.android.lawfirm.R.id.head_right;
import static cn.lf.android.lawfirm.R.id.right_one;

public class NoticeAdapter extends BaseAdapter {
    private List<Message> list;
    private LayoutInflater inflater;
    private Activity context;
    private int mPosition = 0;

    public NoticeAdapter(Activity context, List<Message> list) {
        this.context = context;
        this.list = list;
        this.inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.item_notice, null);
            holder.tv_content = (TextView) convertView
                    .findViewById(R.id.tv_content);
            holder.head_right = (TextView) convertView
                    .findViewById(head_right);
            holder.head_left = (TextView) convertView
                    .findViewById(head_left);
            holder.right_one = (TextView) convertView
                    .findViewById(right_one);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        final Message bean = list.get(position);

        holder.tv_content.setText(bean.Content);
        holder.head_left.setText(bean.Title);
        holder.head_right.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ((NoticeListActivity) context).doKnow(position);
            }
        });
        if ("承办审批".equals(bean.Title)||"合同变更".equals(bean.Title)||"律师分派".equals(bean.Title)||"新增审级".equals(bean.Title)||"外出登记".equals(bean.Title)) {
            holder.head_left.setTextColor(0xffff6468);
        } else{
            holder.head_left.setTextColor(0xff333333);
        }
        return convertView;
    }

    class ViewHolder {
        TextView head_left, head_right, tv_content, right_one;
    }

}
